<?php
include_once('common/header.php');			
if($AppUI->id <=0 || !isset($_SERVER['HTTP_REFERER'])) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$intOfflineId	= $objRequest->getParam('pofflineid', 0);
$strTitle 		= $objRequest->getParam('ptitle', '');
$intCategoryId	= $objRequest->getParam('pcategoryid', 0);
$intQuantity	= $objRequest->getParam('pquantity', 0);
$strExpired		= $objRequest->getParam('pexpired', '');
$strHours		= $objRequest->getParam('phours', '');
$strMinutes		= $objRequest->getParam('pminutes', '');
$intProvince	= $objRequest->getParam('pprovince', 0);
$intDistrict	= $objRequest->getParam('pdistrict', 0);
$strAddress		= $objRequest->getParam('paddress', '');
$strMobile		= $objRequest->getParam('pmobile', '');
$strYahoo		= $objRequest->getParam('pyahoo', '');
$strSkype		= $objRequest->getParam('pskype', '');
$strContent		= $objRequest->getParam('pcontent', '');
$strContent		= Vfriend_Function::stripTags($strContent,0);
$intSrcId		= $objRequest->getParam('psrcid', 0);
$intError		= 0;
if($strTitle == '') $intError = 1;
elseif($strTitle != '' && strlen($strTitle) < 5) $intError = 2;
elseif($intCategoryId == 0) $intError = 3;
elseif($intQuantity != "" && $intQuantity > 100) $intError=4;
elseif($strExpired != "" && !Vfriend_Function::isValidDate($strExpired)) $intError=5;
elseif(($strHours != "" || $strMinutes != "") && ($strExpired == "" || !Vfriend_Function::isValidHour($strHours,$strMinutes))) $intError=6;
elseif(($strHours != "" && strlen($strHours) != 2) || ($strMinutes != "" && strlen($strMinutes) != 2)) $intError=6;
elseif($intProvince == "" || $intProvince == 0) $intError=7;
elseif($intDistrict == "" || $intDistrict == 0) $intError=8;
elseif($strAddress == "") $intError=9;
elseif($strContent == "") $intError=10;
elseif($strContent != "" && strlen($strContent) < 20) $intError=11;
if($intError == 0) {
	if(isset($_SESSION['sOfflineError'])) unset($_SESSION['sOfflineError']);
	if(isset($_SESSION['sOfflineParam'])) unset($_SESSION['sOfflineParam']);
	$strShort 		= Vfriend_Function::wordCut($strContent);
	if($strExpired != '') {
		$strExpired = Vfriend_Function::convertStrToDate($strExpired);
		if($strHours && $strMinutes) {
			$strExpired .= ' ' . $strHours . ':' . $strMinutes . ':00';
		}
	}
	$objOffline		= new Offline();
	$intError		= $objOffline->update($AppUI->id, $intOfflineId, $intCategoryId, $strTitle, $strContent, $strShort, $intQuantity, COUNTRY_DEFAULT, $intProvince, $intDistrict, $strAddress, $intSrcId, $strExpired, $strMobile, $strYahoo, $strSkype);
	if($intError == 0 ) {
		$strLink = Vfriend_Function::linkOfflineForDetail($intOfflineId, $strTitle);
		Vfriend_Function::setMsg($arrMessage[7]);
		Vfriend_Function::redirect($strLink);
		exit();
	} else {
		$intError	= 20+$intError;
	}
}
if($intError > 0) {
	$_SESSION['sOfflineError']	= $arrError[$intError];
	$_SESSION['sOfflineParam']	= $objRequest->getParams();	
}
Vfriend_Function::redirect(LINK_OFFLINE_EDIT . '?offlineid=' . $intOfflineId);
exit();
?>